home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / DebugTool_111.lha / srcdecode.c < prev    next >
C/C++ Source or Header  |  1992-06-02  |  3KB  |  151 lines

  1. #include "frobnitz.h"
  2.  
  3. byte alph[4];
  4. byte macro[4];
  5. byte ascii_tab;
  6.  
  7. /*******************************************************************/
  8. /*  Funktion: StringDecode                                         */
  9. /*******************************************************************/
  10.  
  11. void
  12. StringDecode (void)
  13. {
  14.   short int i;
  15.   int m;
  16.  
  17.   DecodeReset ();
  18.   alph[1] = 1;
  19.   PrintedChars = 0;
  20.  
  21.   for (i = 1; i <= EncodedString[0]; i++)
  22.     {
  23.       if (i > (MAXLEN_ENCSTR - 1))
  24.     quit (6);
  25.  
  26.       m = EncodedString[i];
  27.       if (ascii_tab)
  28.     {
  29.       i++;
  30.       m = 32 * (m & 0x07) + (EncodedString[i] & 0x1f);
  31.     }
  32.       ExChar (m);
  33.     }
  34.  
  35.   DecodedString[PrintedChars] = '\0';
  36.  
  37.   if (PrintedChars > (MAXLEN_DECSTR - 1))
  38.     quit (7);
  39. }
  40.  
  41. /*******************************************************************/
  42. /*  Funktion: ExChar                                               */
  43. /*******************************************************************/
  44.  
  45. int
  46. ExChar (int m)
  47. {
  48.   int i;
  49. /* ACHTUNG : Macros zuerst ! */
  50.  
  51.   for (i = 1; i < 4; i++)
  52.     {
  53.       if (macro[i])
  54.     {
  55.       DecodeReset ();
  56.       alph[1] = 1;
  57.       PrintMacro ((i - 1), m);
  58.       DecodedString[PrintedChars] = '\0';
  59.       strcat (DecodedString, MacroString);
  60.       PrintedChars = strlen (DecodedString);
  61.       return m;
  62.     }
  63.     }
  64.  
  65.   if (m == 0)
  66.     {
  67.       DecodedString[PrintedChars] = ' ';
  68.       PrintedChars++;
  69.       return m;
  70.     }
  71.  
  72.   for (i = 1; i < 4; i++)
  73.     {
  74.       if (m == i)
  75.     {
  76.       DecodeReset ();
  77.       macro[i] = 1;
  78.       return m;
  79.     }
  80.     }
  81.  
  82.   if (m == 4)
  83.     {
  84.       for (i = 1; i < 4; i++)
  85.     {
  86.       if (alph[i])
  87.         {
  88.           DecodeReset ();
  89.           alph[2 - (i == 3)] = 1;
  90.           return m;
  91.         }
  92.     }
  93.     }
  94.  
  95.   if (m == 5)
  96.     {
  97.       for (i = 1; i < 4; i++)
  98.     {
  99.       if (alph[i])
  100.         {
  101.           DecodeReset ();
  102.           alph[3 - 2 * (i == 2)] = 1;
  103.           return m;
  104.         }
  105.     }
  106.     }
  107.  
  108.   if (m > 5)
  109.     {
  110.       for (i = 1; i < 4; i++)
  111.     {
  112.       if (alph[i])
  113.         {
  114.           DecodeReset ();
  115.           if ((i == 3) && (m == 6))
  116.         ascii_tab = 1;
  117.           else
  118.         {
  119.           DecodedString[PrintedChars] = alphabet[i - 1][m - 6];
  120.           PrintedChars++;
  121.           alph[1] = 1;
  122.         }
  123.           return m;
  124.         }
  125.     }
  126.     }                /* m> 5 */
  127.  
  128.   if (ascii_tab)
  129.     {
  130.       DecodedString[PrintedChars] = m;
  131.       PrintedChars++;
  132.       DecodeReset ();
  133.       alph[1] = 1;
  134.       return m;
  135.     }
  136.  
  137.   printf ("ERR");
  138.   return m;
  139. }
  140.  
  141.  
  142. /*******************************************************************/
  143. /*  Funktion: DecodeReset                                          */
  144. /*******************************************************************/
  145.  
  146. void
  147. DecodeReset (void)
  148. {
  149.   alph[1] = alph[2] = alph[3] = macro[1] = macro[2] = macro[3] = ascii_tab = 0;
  150. }
  151.